#1、try...except...语句
#如果try中的语句没有异常，则执行try，不执行except
#如果try中的语句有异常，则不执行try中异常语句以及异常语句之后的语句，跳转执行except
# try:
#     print('呵呵')
#     print(abc)
#     print('无敌了孩子')
# except:
#     print('哦豁，代码出错啦!')

#2、try...except...else...finally 语句
#try语句正常，执行try...else...finally
#try语句异常，执行except...finally
# try:
#     a=int(input('请输入第一个整数'))
#     b=int(input('请输入第二个整数'))
#     result=a/b
# except:
#     print('输入错误')
# else:
#     print(result)
# finally:
#     print('程序结束')

#3、异常信息捕获，异常exception
    #NameError: name 'a' is not defined
try:
    print(a)
except Exception as e:      #利用Exception抓取异常信息，取另外为e
    print('程序出错')
    print(f'异常类型:{type(e)}')
    print(f'异常类型:{type(e).__name__}')
    print(f'异常信息:{e}')
    print(f'{type(e)}:{e}')
    print(f'{type(e).__name__}:{e}')


# try:
# # print(a)
# # lst=['a','b','c']# print(lst[3])
# # a='1'+2
# # a=int('3.14')
#     a=5/0
# except NameError as e:
    # print('变量或函数没有定义')
    # print(f'{type(e).__name__}:{e}')except IndexError as e:
    # print('下标超出了范围')
    # print(f'{type(e).__name__}:{e}')except TypeError as e:
    # print('数据类型错误")
    # print(f'{type(e).__name__}:{e}')except ValueError as e:
    # print('值错误')
    # print(f'{type(e).__name__}:{e}')except Exception as e:
    # print('其它错误')
    # print(f'{type(e).__name__}:{e}')